#商品页面
import time

from appium.webdriver.common.appiumby import AppiumBy

from basic.base_assert import current_page
from basic.base_page import BasePage


class PageShopping(BasePage):

    def buy_now(self):
        pass

    def add_to_cart(self):
        # el4 = self.driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR,
        #                           value="new UiSelector().resourceId(\"com.xiaomi.shop:id/content_container\").instance(0)")
        # el4._click()
        add_cart_locator ="new UiSelector().text(\"加入购物车\")"
        self._click(add_cart_locator)

        time.sleep(5)

        # confirm_locator = "new UiSelector().text(\"加入购物车\")"
        # self._click(confirm_locator)

        confirm_locator = "new UiSelector().className(\"android.view.ViewGroup\").instance(52)"
        self._click(confirm_locator)


        time.sleep(5)
        return self

    def collection(self):
        pass

    def goto_shopping_cart(self):
        shopping_cart_locator = "new UiSelector().text(\"购物车\")"
        self._click(shopping_cart_locator)

        time.sleep(5)

        return current_page()

        # shopping_cart_edit= "new UiSelector().text(\"编辑\")"
        # self._click(shopping_cart_edit)
        #
        # shopping_cart_select = "new UiSelector().className(\"android.widget.ImageView\").instance(1)"
        # self._click(shopping_cart_select)
        #
        # shopping_cart_del = "new UiSelector().className(\"android.view.ViewGroup\").instance(36)"
        # self._click(shopping_cart_del)
        #
        # shopping_cart_confirm = "new UiSelector().className(\"android.view.ViewGroup\").instance(8)"
        # self._click(shopping_cart_confirm)


if __name__ == '__main__':
    from page.page_main import PageMain
    page_main = PageMain()
    page_main.goto_new_arrivals().new_calendar_update_goto_shopping_cart().add_to_cart().goto_shopping_cart()
